package com.ymatou.iapi.payment.testcase;

import java.math.BigDecimal;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.ymatou.iapi.payment.parameter.RegFqlMemberBean;
import com.ymatou.iapi.payment.service.RegFqlMemberCall;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.business.service.PayGateWayCallService;
import com.ymttest.database.model.FqlMember;
import com.ymttest.database.model.FqlMemberExample;
import com.ymttest.database.sqlwapper.PayGateWayWapper;
/**
*分期乐会员注册
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_RegFqlMember{
	private static RegFqlMemberBean regfqlmemberBean;
	private static RegFqlMemberCall regfqlmemberCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("分期乐会员注册");
	}

	@Before
	public void caseUp() {
		regfqlmemberBean=new RegFqlMemberBean();
		regfqlmemberCall=new RegFqlMemberCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(regfqlmemberCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	//用户已经切换到线上-SIT不支持支付了
	public void Tc_RegFqlMember_001() {
		Logger.start(true,"分期乐会员注册成功-有手机号");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			int uid  = urrc.getUserid();
			regfqlmemberBean.setUserId(uid);
			regfqlmemberCall.setData(regfqlmemberBean);
			regfqlmemberCall.callService();			
			Logger.verifyEquals("0", regfqlmemberCall.getString("ErrorCode"), "验证ErrorCode");
			FqlMemberExample example=new FqlMemberExample();
			example.createCriteria().andUserIdEqualTo(regfqlmemberBean.getUserId());
			List<FqlMember> dbs = new PayGateWayWapper().selectFqlMemberExample(example);
			Logger.verifyEquals(1, dbs.size(), "验证数据进入数据库");
			//Thread:main 2019-06-25 17:19:17.637 返回报文{"ErrorCode":0,"ErrorMessage":null,"IsSuccess":true,"Result":{"token":"T20190625a6ec613612eee4020e8c1a72563ba0e1","phone":"13396797142","agent":"1090986","reserve_order_id":"","third_uid":"2","scene":"2","channel":"leka","client_id":"ceshisan","flag":"1","scope":"snsapi_base","modify_phone":"0"}}
			Logger.debug(FormatUtil.beanToGSONString(dbs));
			JsonObject result = regfqlmemberCall.getJsonObject().get("Result").getAsJsonObject();
			Logger.verifyEquals(PayGateWayCallService.FQLAgent, result.get("agent").getAsInt(), "验证agent");
			Logger.verifyEquals(regfqlmemberBean.getUserId(), result.get("third_uid").getAsInt(), "验证third_uid");
			Logger.verifyEquals(regbean.getLoginMobile(), result.get("phone").getAsString(), "验证phone");
			Logger.verifyEquals(false,result.get("token").isJsonNull(), "验证token");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_RegFqlMember_002() {
		Logger.start(true,"不输入userid失败");
		try {
			regfqlmemberCall.setData(regfqlmemberBean);
			regfqlmemberCall.callService();			
			Logger.verifyEquals("1000", regfqlmemberCall.getString("ErrorCode"), "验证ErrorCode");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_RegFqlMember_003() {
		Logger.start(true,"输入不存在userid失败");
		try {
			regfqlmemberBean.setUserId(-99999);
			regfqlmemberCall.setData(regfqlmemberBean);
			regfqlmemberCall.callService();			
			Logger.verifyEquals("1000", regfqlmemberCall.getString("ErrorCode"), "验证ErrorCode");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	//用户已经切换到线上-SIT不支持支付了
	public void Tc_RegFqlMember_004() {
		Logger.start(true,"分期乐会员注册用户无手机号");
		try {
			regfqlmemberBean.setUserId(92);
			regfqlmemberCall.setData(regfqlmemberBean);
			regfqlmemberCall.callService();			
			Logger.verifyEquals("0", regfqlmemberCall.getString("ErrorCode"), "验证ErrorCode");
			JsonObject result = regfqlmemberCall.getJsonObject().get("Result").getAsJsonObject();
			Logger.verifyEquals(null, result.get("phone"), "验证phone");
			Logger.verifyEquals("", result.get("token").getAsString(), "验证token");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	//用户已经切换到线上-SIT不支持支付了
	public void Tc_RegFqlMember_005() {
		Logger.start(true,"分期乐会员注册用户带FqlToken");
		try {
			regfqlmemberBean.setUserId(200);
			regfqlmemberBean.setFqlToken("token22");
			regfqlmemberCall.setData(regfqlmemberBean);
			regfqlmemberCall.callService();			
			Logger.verifyEquals("0", regfqlmemberCall.getString("ErrorCode"), "验证ErrorCode");
			JsonObject result = regfqlmemberCall.getJsonObject().get("Result").getAsJsonObject();
			Logger.verifyEquals(null, result.get("phone"), "验证phone");
			Logger.verifyEquals(regfqlmemberBean.getFqlToken(), result.get("token").getAsString(), "验证token");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}